package com.itboye.jinpuyiyuan.utils.logincontroller;


import android.app.Activity;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.text.TextUtils;
import android.util.Log;

import com.alibaba.mobileim.IYWLoginService;
import com.alibaba.mobileim.IYWP2PPushListener;
import com.alibaba.mobileim.IYWTribePushListener;
import com.alibaba.mobileim.YWAPI;
import com.alibaba.mobileim.YWIMKit;
import com.alibaba.mobileim.YWLoginParam;
import com.alibaba.mobileim.channel.constant.B2BConstant;
import com.alibaba.mobileim.channel.event.IWxCallback;
import com.alibaba.mobileim.channel.util.AccountUtils;
import com.alibaba.mobileim.channel.util.WxLog;
import com.alibaba.mobileim.contact.IYWContact;
import com.alibaba.mobileim.conversation.IYWConversationService;
import com.alibaba.mobileim.conversation.YWConversation;
import com.alibaba.mobileim.conversation.YWCustomMessageBody;
import com.alibaba.mobileim.conversation.YWMessage;
import com.alibaba.mobileim.gingko.model.tribe.YWTribe;
import com.alibaba.mobileim.utility.IMNotificationUtils;
import com.alibaba.tcms.env.EnvManager;
import com.alibaba.tcms.env.TcmsEnvType;
import com.alibaba.tcms.env.YWEnvManager;
import com.alibaba.tcms.env.YWEnvType;
import com.itboye.jinpuyiyuan.MainActivity;
import com.itboye.jinpuyiyuan.app.MyApplication;
import com.itboye.jinpuyiyuan.utils.sputil.Const;
import com.itboye.jinpuyiyuan.utils.sputil.SPUtils;
import com.umeng.message.PushAgent;
import com.umeng.message.UTrack;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.List;

import static com.itboye.jinpuyiyuan.utils.IMKit.LoginSampleHelper.APP_KEY_TEST;


/**
 * 登录相关控制类--状态模式</br></br>
 * <p>
 * 登录成功后调用setLoginState(new LoginedState());</br></br>
 * 退出登录后调用setLoginState(new UnLoginState());</br></br>
 * 进入主Activity前一定要设置一次，要么登录要么未登录</br></br>
 *
 * @author Mr.w
 */
public class LoginController {

    private static ILoginState loginState = new UnLoginState();
    private static PushAgent mPushAgent;


    public static void setLoginState(ILoginState loginState) {

        LoginController.loginState = loginState;
        if (loginState instanceof UnLoginState) {
            Log.d("LoginLoginLoginLogin", "未登录");
        } else if (loginState instanceof LoginedState) {
            Log.d("LoginLoginLoginLogin", "已登录。。。");

            mPushAgent = MyApplication.getInstance().getmPushAgent();
            // mPushAgent.setPushIntentServiceClass(MyPushIntentService.class);
            mPushAgent.onAppStart();

            String uid = (String) SPUtils.get(MyApplication.instatnce, null,
                    Const.UID, "");

            Log.d("====uid===",uid+"");
            mPushAgent.addExclusiveAlias(uid, Const.UMENG_ALIAS, new UTrack.ICallBack() {
                @Override
                public void onMessage(boolean arg0, String arg1) {
                    // TODO Auto-generated method stub
                    System.out.println(arg0 + "arg222" + arg1);
                }
            });


        }
    }

    /**
     * 个人信息
     */
    public static void PersonnalInfomaton(Activity activity, Object data) {
        loginState.PersonnalInfomaton(activity, data);
    }

}
